/**
 * Created by siguangyi on 17/4/6.
 */
model={
    //工具列表，单个模型
    toolModel:'<a class="toolModel b_edge blockInline">' +
    '<section class="toolImg"><img class="preImg"  src="" /></section>' +
    '<section class="toolDetail">' +
    '<section class="detailLine one"><span class="toolName">21321312</span></section>' +
    '<section class="detailLine second"><span class="toolIntroduce">1321321</span></section>' +
    '<section class="detailLine second"><span class="toolTips">321312</span></section>' +
    '</section>' +
    '</a>',
}

// 获取任务列表
function getToolList() {
    var url="/api/Tools/toolList";
    var listener = toolListBack;

    var formdata={};

    formdata.pageNum        = 1;
    formdata.numPerPage     = 30;
    formdata.toolLabel      = 1;
    formdata.clientType     = 1;
    formdata.findType       = 2;
    formdata.state          = 1;

    Request("POST",JSON.stringify(formdata),url,listener);
}

function toolListBack(resultObject){
    $(".footer-http-wait").css({
        display:"none"
    });

    if( !resultObject || resultObject.code != 200) {
        $(".toolList").append('<span class="special_tag">查询失败，请返回重试.......</span>');
    }
    else{
        var data = resultObject.data;
        var toolResult = null;
        if(data) {
            toolResult = data.recordList;
        }

        if( !toolResult || toolResult.length<1) {
            $(".toolList").append('<span class="special_tag">您暂时没有收到任务.......</span>');
        }

        var one;
        //列表排序
        for(var i=0;i<toolResult.length;i++){
            for(var j=i+1;j<toolResult.length;j++)
                if(toolResult[j].createTime>toolResult[i].createTime){
                    one=toolResult[i];
                    toolResult[i]=toolResult[j];
                    toolResult[j]=one;
                }
        }

        for(var i=0;i<toolResult.length;i++){
            var $mode=$(model.toolModel);
            var single=toolResult[i];

            var price = single.toolPrice;

            //SGYTEST
//            if(price <= 0)
 //           {
                $mode.attr("href","/Tool/toolDetail?tToolId="+single.id);
                $mode.find(".toolName").text(single.toolName);

                if(single.listMinUrlApp==null||single.listMinUrlApp==undefined||single.listMinUrlApp.length < 4)
                {
                    $mode.find(".preImg").attr("src","/resources/images/moren.png");
                }
                else
                {
                    $mode.find(".preImg").attr("src",single.listMinUrlApp);
                }

                var toolSide = single.toolsSide;
                if(toolSide )
                {
                    $mode.find(".toolIntroduce").text(toolSide.toolRemark1);
                    $mode.find(".toolTips").text(toolSide.toolRemark2);
                }

                $(".toolList").append($mode);
            //SGYTEST           }
        }
    }
}

